﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title>ProductDetail</title>
	<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
	<script src="../../Scripts/kindeditor-all-min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../Scripts/kindeditor_zh_cn.js"></script>
	<link rel="stylesheet" href="../../Content/kindeditor_default/default.css" />
	<script type="text/javascript">

		var editor;
		KindEditor.ready(function (K) {
			editor = K.create('textarea[name="Content"]', {
				resizeType: 1,
				allowPreviewEmoticons: true,
				allowImageUpload: true,
				allowFileManager: true,
				allowUpload: true,
				fileManagerJson: '/Admini/UploadImage',
				uploadJson: '/Admini/UploadImage',
				items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
						'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
						'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
						'superscript', 'clearhtml', 'quickformat', 'selectall', '|',
						'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
						'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
						 'table', 'hr', 'pagebreak',
						'anchor', 'link', 'unlink', '|', 'about']
			});
		});

		$(document).ready(function () {
			var id = $("#pID").val();
			if (id != "") {
				// get productmsg
				$.ajax({
					url: "/Products/GetProductByID",
					data: { id: id },
					cache: false,
					success: function (data) {
						if (data != undefined) {
							$("#id").val(data.ID);
							$("#productClass").val(data.ClassID);
							$("#productName").val(data.ProductName);
							$("#showIndex").val(data.ShowIndex);
							editor.insertHtml(data.Description);
							$("#showInClass").val(data.ShowInClass);
						}
					},
					error: function (data) {
					}
				});
			}
			else {
				$("#productClass").val($("#classID").val());
				alert("111");
			}
		});

		function save() {
			var id = $("#id").val();
			if (id == "") {
				id = 0;
			}
			var classid = parseInt($("#productClass").val());
			var productName = $("#productName").val();
			var showindex = parseInt($("#showIndex :selected").val());
			var description = editor.html();
			var showInClass = parseInt($("#showInClass :selected").val());
			$.ajax({
				url: "/Admini/SaveProduct",
				cache: false,
				data: { ID: id, ClassID: classid, ShowIndex: showindex, ShowIndexClass: showInClass, productName: productName, description: description },
				success: function (data) {
					alert("Save Success");
					location.href("/Admini/Products");
				},
				error: function (data) {
					alert();
				}
			});
		} 
	</script>
</head>
<body>
	<input type="hidden" name="name" id="pID" value="<%=ViewData["ID"] %>" />
	<input type="hidden" name="name" id="classID" value="<%=ViewData["classID"]  %>" />
	<div>
		<div>
			<input type="hidden" name="" value="" id="id" />
			<input type="text" name="" value="" id="productClass" readonly="readonly" style="display: none" />
			Product Name:<input type="text" name="" value="" id="productName" />
			<input type="hidden" name="" value="" id="classid" />
			ShowInIndex:<select id="showIndex">
				<option value="0">No</option>
				<option value="1">Yes</option>
			</select>
			ShowInClass:<select id="showInClass">
				<option value="0">No</option>
				<option value="1">Yes</option>
			</select>
			<input type="button" name="" value="Save" onclick="save()" />
			<input type="button" name="" value="Cancel" onclick="cancel()" />
		</div>
		<textarea id="txtContent" name="Content" cols="80" rows="40"></textarea></div>
</body>
</html>
